package com.lw.sbdemo2.common.exception;

import lombok.extern.slf4j.Slf4j;

/**
 * <p>标题: 自定义异常类</p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2018</p>
 * <p>公司: 智业软件</p>
 *
 * @author LinWang
 * @date 2018-02-25 14:34
 */
@Slf4j
public class ApiException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    /**
     * 异常类型
     */
    private ResponseCodeEnum code = ResponseCodeEnum.EX_ERROR;

    /**

     * 详细错误
     */
    private String errorMessage;

    public ApiException(String message) {
        super(message);
        log.error("抛出ApiException异常：{}", message);
        this.setErrorMessage(message);
    }

    public ApiException(String code, String message) {
        super(code + ":" + message);
        log.error("抛出ApiException异常：{}", message);
        this.setErrorMessage(message);
    }

    public ApiException(ResponseCodeEnum reqCode, String message) {
        super(reqCode.getCode() + "：" + reqCode.getMessage() + "：" + message);
        log.error("抛出ApiException异常：{}", message);
        this.setErrorMessage(reqCode.getMessage() + "：" + message);
        this.setCode(reqCode);
    }

    public ResponseCodeEnum getCode() {
        return code;
    }

    public void setCode(ResponseCodeEnum code) {
        this.code = code;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

}
